import time,re
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from Common import readexcelcasetobug
# from casetobug import casetobug
# import xlwings as xw
# import os

class DelCaseElement(object):
    def __init__(self,driver):
        #私有方法
        self.driver = driver

    def switch_newest_window(self):
        #切换到最新的窗口
        time.sleep(2)
        eles = self.driver.window_handles
        self.driver.switch_to.window(eles[-1])


    def operate_enter(self):
        # 利用键盘操作enter
        time.sleep(2)
        ActionChains(self.driver).send_keys(Keys.ENTER).perform()

    def operate_down(self):
        # 利用键盘操作enter
        time.sleep(2)
        ActionChains(self.driver).send_keys(Keys.ARROW_DOWN).perform()

    def close_cur_window(self):
        #关闭当前窗口
        self.driver.close()

    def operate_pagedown(self):
        # 利用键盘操作enter
        time.sleep(2)
        ActionChains(self.driver).send_keys(Keys.PAGE_DOWN).perform()

    def operate_doubleclick(self,ele):
        # 利用键盘操作双击
        time.sleep(2)
        ActionChains(self.driver).double_click(ele).perform()

    def frame_to_tobug(self):
        #转bug弹框页面,获取frame
        ele = self.driver.find_element_by_xpath('//iframe[@id="iframe-triggerModal"]')
        self.driver.switch_to.frame(ele)

    def frame_to_reprosteps(self):
        #提bug页面,获取重现步骤栏frame
        ele = self.driver.find_element_by_xpath('//iframe[@class="ke-edit-iframe"]')
        self.driver.switch_to.frame(ele)

    def find_article_content(self):
        #提bug页面,重现步骤栏富文本
        ele = self.driver.find_element_by_xpath('//body[@class="article-content"]')
        return ele



    def frame_to_default(self):
        self.driver.switch_to.default_content()  # 切换到默认frame
        time.sleep(2)

    def frame_to_parent(self):
        self.driver.switch_to.parent_frame()  # 切换到父级frame

    ##以下是登录页面
    def find_account_textbox(self):
        # 查找并返回鸿信门户账户输入框
        ele = self.driver.find_element_by_id('loginId')
        return ele

    def find_password_textbox(self):
        # 查找并返回鸿信门户密码输入框
        ele = self.driver.find_element_by_id('password')
        return ele

    def find_submit_button(self):
        # 查找并返回鸿信门户登录按钮
        ele = self.driver.find_element_by_xpath('//div[@id="login"]/a[2]')
        return ele

    ##以下是登录首页
    def find_xiaoneng_button(self):
        # 查找并返回效能平台按钮
        ele = self.driver.find_element_by_xpath('//ul[@id="daohang"]/li[6]/a')
        return ele

    ##以下是鸿信效能平台
    def find_chandao_button(self):
        # 查找并返回禅道按钮
        ele = self.driver.find_element_by_xpath('//div[@class="l-layout-header-menu"]//li[2]/div')
        return ele

    ##以下是禅道首页
    def find_ceshi_button(self):
        # 查找并返回测试按钮
        ele = self.driver.find_element_by_xpath('//li[@data-id="qa"]')
        return ele



    #以下是禅道测试首页
    def find_yongli_button(self):
        # 查找并返回用例按钮
        ele = self.driver.find_element_by_xpath('//li[@data-id="testcase"]/a')
        return ele

    def find_bug_button(self):
        # 查找并返回bug按钮
        ele = self.driver.find_element_by_xpath('//li[@data-id="bug"]/a')
        return ele

    def find_ceshidan_button(self):
        # 查找并返回测试单按钮
        ele = self.driver.find_element_by_xpath('//li[@data-id="testtask"]/a')
        return ele

    ##以下是禅道测试,用例页面
    def find_currentItem_button(self):
        #查找并返回测试主页选项按钮
        ele = self.driver.find_element_by_id('currentItem')
        return ele

    def find_currentItem_textbox(self):
        #查找并返回测试主页搜索文本框
        ele = self.driver.find_element_by_xpath('//button[@id="currentItem"]/following-sibling::div//input')
        return ele

    ##以下是禅道测试,测试单页签
    def find_ceshidan_case1_button(self):
        #查找并返回测试主页测试单页签，第一行测试单中的用例按钮
        ele = self.driver.find_element_by_xpath('(//div[@id="action-divider"]/a[1])[1]')
        return ele

    def find_ceshidan_case2_button(self):
        #查找并返回测试主页测试单页签，第二行测试单中的用例按钮
        ele = self.driver.find_element_by_xpath('(//div[@id="action-divider"]/a[1])[2]')
        return ele

    def find_ceshidan_case3_button(self):
        #查找并返回测试主页测试单页签，第三行测试单中的用例按钮
        ele = self.driver.find_element_by_xpath('(//div[@id="action-divider"]/a[1])[3]')
        return ele

    def find_ceshidan_case4_button(self):
        #查找并返回测试主页测试单页签，第四行测试单中的用例按钮
        ele = self.driver.find_element_by_xpath('(//div[@id="action-divider"]/a[1])[4]')
        return ele

    ###以下是测试单用例页面元素
    def find_cur_result(self):
        # 筛选出用例的结果
        ele = self.driver.find_element_by_xpath('(//tbody)[5]//td[9]/span')
        ele_value = ele.text
        print('\n当前用例的执行结果：',ele_value)
        return ele_value
    def find_cur_case(self):
        # 筛选出的一条用例
        ele = self.driver.find_element_by_xpath('//table[@id="caseList"]//tbody')
        return ele


    def find_operation_button(self):
        # 执行按钮元素
        ele = self.driver.find_element_by_xpath('(//div[@class="table-footer"]//button)[4]')
        return ele

    def find_fail_option(self):
        # 失败勾选框
        ele = self.driver.find_element_by_xpath('//input[@value="fail"]')
        return ele

    def find_save_button(self):
        # 保存按钮
        ele = self.driver.find_element_by_xpath('//button[@id="submit"]')
        return ele


    def find_tobug_button(self):
        # 用例列表转bug按钮
        ele = self.driver.find_element_by_xpath('(//tbody)[5]//td[14]/a[1]')
        return ele

    def find_tobug_button_popup(self):
        # 弹框页面转bug按钮
        ele = self.driver.find_element_by_xpath('//button[@class="btn btn-primary createBtn"]')
        return ele

    def find_tobug_close_button_popup(self):
        # 弹框页面转关闭按钮
        ele = self.driver.find_element_by_xpath('//div[@id="triggerModal"]//button')
        return ele

    ##以下是禅道测试,bug页签
    def find_addbug_button(self):
        #查找并返回测试主页bug页签提bug按钮
        ele = self.driver.find_element_by_xpath('//div[@id="mainMenu"]/div[3]/a[4]')
        return ele

    ###以下是提bug页面元素
    def find_bugtitle_textbox(self):
        #提bug页面,查找并返回bug标题
        ele = self.driver.find_element_by_xpath('(//input[@id="title"])[1]')
        return ele

    def find_iteration_select(self):
        #提bug页面,查找并返回所属迭代可点击操作框
        ele = self.driver.find_element_by_xpath('//select[@id="openedBuild"]')
        return ele

    def find_iteration_button(self):
        #提bug页面,查找并返回所属迭代可点击操作框
        ele = self.driver.find_element_by_xpath('//span[@id="projectIdBox"]')
        return ele

    def find_iteration_textbox(self):
        #提bug页面,查找并返回所属迭代文本输入框
        ele = self.driver.find_element_by_xpath('//select[@id="project"]/following-sibling::div//input')
        return ele

    def find_infversion_button(self):
        #提bug页面,查找并返回影响版本可点击操作框
        ele = self.driver.find_element_by_xpath('//select[@id="openedBuild"]/following-sibling::div/ul')
        return ele

    def find_infversion_textbox(self):
        #提bug页面,查找并返回影响版本文本输入框
        ele = self.driver.find_element_by_xpath('//select[@id="openedBuild"]/following-sibling::div//input')
        return ele

    def find_infversion_chosen_ele(self):
        #提bug页面,查找并返回影响版本可点击操作框
        ele = self.driver.find_element_by_xpath('//div[@id="buildBox"]/div[1]//ul[@class="chosen-results"]/li[1]')
        return ele

#//select[@id="openedBuild"]/following-sibling::div[1]/div//li[1]
#//div[@id="buildBox"]/div[1]//ul[@class="chosen-results"]/li[1]
    def find_curappoint_button(self):
        #提bug页面,查找并返回当前指派可点击操作框
        ele = self.driver.find_element_by_xpath('//select[@id="assignedTo"]/following-sibling::div/a')
        return ele

    def find_curappoint_textbox(self):
        #提bug页面,查找并返回当前指派文本输入框
        ele = self.driver.find_element_by_xpath('//select[@id="assignedTo"]/following-sibling::div//input')
        return ele

    def find_severity_button(self):
        #提bug页面,查找并返回严重程度按钮
        ele = self.driver.find_element_by_xpath('//div[@class="input-group title-group"]/div[2]/button')
        return ele

    def find_priority_button(self):
        #提bug页面,查找并返回优先级按钮
        ele = self.driver.find_element_by_xpath('//div[@class="input-group title-group"]/div[3]/button')
        return ele

    def find_severity_choice1(self):
        #提bug页面,查找并返回严重程度选项
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[1]/span[1]')
        return ele

    def find_severity_choice2(self):
        #提bug页面,查找并返回严重程度选项2
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[1]/span[2]')
        return ele

    def find_severity_choice4(self):
        #提bug页面,查找并返回严重程度选项4
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[1]/span[4]')
        return ele

    def find_priority_choice1(self):
        #提bug页面,查找并返回优先级选项1
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[2]/span[1]')
        return ele

    def find_priority_choice2(self):
        #提bug页面,查找并返回优先级选项2
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[2]/span[2]')
        return ele

    def find_priority_choice4(self):
        #提bug页面,查找并返回优先级选项4
        ele = self.driver.find_element_by_xpath('(//div[@class="label-selector"])[2]/span[4]')
        return ele

    def find_storyIdBox_button(self):
        #提bug页面,查找并返回相关研发需求可点击操作框
        ele = self.driver.find_element_by_xpath('//span[@id="storyIdBox"]')
        return ele

    def find_storyIdBox_textbox(self):
        #提bug页面,查找并返回相关研发需求文本输入框
        ele = self.driver.find_element_by_xpath('//select[@id="story"]/following-sibling::div//input')
        return ele


    def find_bugsubmit_button(self):
        #提bug页面,查找并返回保存按钮
        ele = self.driver.find_element_by_xpath('//button[@id="submit"]')
        return ele

    def find_bugreturn_button(self):
        #提bug页面,查找并返回返回按钮
        ele = self.driver.find_element_by_xpath('(//input[@id="uid"]/following-sibling::a)[2]')
        return ele

    ###以下是用例页签下的元素
    def find_bysearchTab_button(self):
        #查找并返回测试主页用例页面搜索按钮
        ele = self.driver.find_element_by_id('bysearchTab')
        return ele

    def find_field1_chosen_button(self):
        # 查找并返回测试主页用例页面搜索，第一组选项按钮
        ele = self.driver.find_element_by_xpath('//div[@id="field1_chosen"]/a')
        return ele

    def find_field1_chosen_selectoption(self):
        # 查找并返回测试主页用例页面搜索，第一组选项
        ele = self.driver.find_element_by_xpath('//select[@id="field1"]')
        return ele

    def find_field1_chosen_optionbox(self):
        # 查找并返回测试主页用例页面搜索，第一组选项框
        ele = self.driver.find_element_by_xpath('//div[@id ="field1_chosen"]//input')
        return ele

    def find_field1_judge_selectoption(self):
        # 查找并返回测试主页用例页面搜索，第一组关系判断
        ele = self.driver.find_element_by_xpath('//select[@id="operator1"]')
        return ele

    def find_field1_result_button(self):
        # 查找并返回测试主页用例页面搜索，第一组结果框按钮
        ele = self.driver.find_element_by_id('valueBox1')
        return ele

    def find_field1_result_textbox(self):
        # 查找并返回测试主页用例页面搜索，第一组结果输入框
        ele = self.driver.find_element_by_xpath('//input[@id="value1"]')
        return ele

    def find_field1_result_spe_textbox(self):
        # 查找并返回测试主页用例页面搜索，第一组结果输入框,在第一组筛选为修改者、由谁创建、执行人时
        ele = self.driver.find_element_by_id('pk_value1-search')
        return ele

    def find_field_result_spe_searched_textbox(self):
        # 查找并返回测试主页用例页面搜索，第一组结果输入框,输入后的查询结构
        ele = self.driver.find_element_by_xpath('//div[@class="picker-option-list"]//span[@class="picker-option-text-matched"]')
        ele_value = ele.text
        print('\n查询后的搜索结果为：',ele_value)
        return ele_value

    def find_fieldlink_judge_selectoption(self):
        # 查找并返回测试主页用例页面搜索，第一组和第二组之间的关系判断
        ele = self.driver.find_element_by_xpath('//select[@id="groupAndOr"]')
        return ele


    def find_field2_chosen_button(self):
        # 查找并返回测试主页用例页面搜索，第二组选项按钮
        ele = self.driver.find_element_by_xpath('//div[@id="field4_chosen"]/a')
        return ele

    def find_field2_chosen_optionbox(self):
        # 查找并返回测试主页用例页面搜索，第二组选项框
        ele = self.driver.find_element_by_xpath('//div[@id ="field4_chosen"]//input')
        return ele



    def find_field2_chosen_selectoption(self):
        # 查找并返回测试主页用例页面搜索，第一组选项
        ele = self.driver.find_element_by_xpath('//select[@id="field4"]')
        return ele

    # def find_field2_judge_button(self):
    #     # 查找并返回测试主页用例页面搜索，第二组关系判断按钮
    #     ele = self.driver.find_element_by_id('operator4')
    #     return ele

    def find_field2_judge_selectoption(self):
        # 查找并返回测试主页用例页面搜索，第一组关系判断
        ele = self.driver.find_element_by_id('operator4')
        return ele

    # def find_field2_chosen_optionbox(self):
    #     # 查找并返回测试主页用例页面搜索，第二组选项框
    #     ele = self.driver.find_element_by_xpath('//div[@id ="field1_chosen"]/a')
    #     return ele

    def find_field2_result_button(self):
        # 查找并返回测试主页用例页面搜索，第二组结果框按钮
        ele = self.driver.find_element_by_id('valueBox4')
        return ele

    def find_field2_result_textbox(self):
        # 查找并返回测试主页用例页面搜索，第二组结果输入框
        ele = self.driver.find_element_by_xpath('//input[@id="value4"]')
        return ele

    def find_field2_result_spe_textbox(self):
        # 查找并返回测试主页用例页面搜索，第二组结果输入框,在第二组筛选为修改者、由谁创建、执行人时
        ele = self.driver.find_element_by_id('pk_value4-search')
        return ele


    def find_case_submit_button(self):
        # 查找并返回测试主页用例页面，搜索按钮
        ele = self.driver.find_element_by_id('submit')
        return ele

    def find_pager_button(self):
        # 查找并返回测试主页用例页面，分页选项按钮
        ele = self.driver.find_element_by_xpath('//ul[@class="pager"]//button[@data-toggle="dropdown"]')
        return ele

    def find_pager_500_button(self):
        # 查找并返回测试主页用例页面，分页选项中的500按钮
        ele = self.driver.find_element_by_xpath('//ul[@class="pager"]//ul/li[13]')
        return ele

    def find_all_CurPageCases_button(self):
        # 查找并返回测试主页用例页面，当前页面所有用例的可点击标题元素
        ele = self.driver.find_elements_by_xpath('//div[@class="datatable-rows"]/div[@style="width: 550px;"]/div//tr')
        return ele

    def find_first_CurPageCase_button(self):
        # 查找并返回测试主页用例页面，当前页面第一条用例的可点击标题元素
        ele = self.driver.find_element_by_xpath('//div[@style="width: 550px;"]//tr[1]/td[last()]/a')
        return ele

    ##以下是用例详情页面
    def find_testCase_detail_delete_button(self):
        # 查找并返回测试主页用例详情页面，删除按钮
        ele = self.driver.find_element_by_xpath('//div[@id="mainContent"]//div[@class="main-actions"]//a[last()]')
        return ele

    def switch_to_alert_accept(self):
        #接受现有弹框---确认删除用例
        time.sleep(1)
        self.driver.switch_to.alert.accept()

class DelCaseElementOper(object):
    def __init__(self,driver):
        #私有方法
        self.chandao_oper = DelCaseElement(driver)

    def switch_2_newest_window(self):
        #切换到最新窗口
        self.chandao_oper.switch_newest_window()

    ##以下是登录页面
    def input_account(self,Account):
        #鸿信门户账户输入框输入账号
        self.chandao_oper.find_account_textbox().send_keys(Account)


    def input_password_textbox(self,Password):
        #鸿信门户密码输入框输入密码
        self.chandao_oper.find_password_textbox().send_keys(Password)

    def click_submit_button(self):
        # 鸿信门户登录按钮,点击
        self.chandao_oper.find_submit_button().click()

    ##以下是登录首页
    def click_xiaoneng_button(self):
        #效能平台按钮,点击
        self.chandao_oper.find_xiaoneng_button().click()

    ##以下是鸿信效能平台
    def click_chandao_button(self):
        #禅道按钮,点击
        self.chandao_oper.find_chandao_button().click()

    ##以下是禅道首页
    def click_ceshi_button(self):
        # 查找并返回测试按钮
        self.chandao_oper.find_ceshi_button().click()

    def click_ceshidan_button(self):
        # 查找并返回测试单按钮
        self.chandao_oper.find_ceshidan_button().click()

    ##以下是禅道测试首页
    def click_yongli_button(self):
        #用例按钮,click
        self.chandao_oper.find_yongli_button().click()

    def click_bug_button(self):
        #bug,click
        self.chandao_oper.find_bug_button().click()

    def click_addbug_button(self):
        #提bug,click
        self.chandao_oper.find_addbug_button().click()

    ##以下是禅道测试用例页面
    def click_currentItem_button(self):
        #测试主页选项按钮,click
        self.chandao_oper.find_currentItem_button().click()

    def input_currentItem_textbox(self,Directory):
        #测试主页搜索文本框,input
        self.chandao_oper.find_currentItem_textbox().send_keys(Directory)

    ##以下是禅道,测试单页面
    def click_ceshidan_case1_button(self):
        #测试单主页，第1行测试单的用例按钮,click
        self.chandao_oper.find_ceshidan_case1_button().click()

    def click_ceshidan_case2_button(self):
        #测试单主页，第2行测试单的用例按钮,click
        self.chandao_oper.find_ceshidan_case2_button().click()

    def click_ceshidan_case3_button(self):
        #测试单主页，第3行测试单的用例按钮,click
        self.chandao_oper.find_ceshidan_case3_button().click()

    def click_ceshidan_case4_button(self):
        #测试单主页，第4行测试单的用例按钮,click
        self.chandao_oper.find_ceshidan_case4_button().click()

    # def get_cur_result(self):
    #     #测试单中的用例页面，获取改用例的结果
    #     self.chandao_oper.find_cur_result()

    def click_cur_case(self):
        #测试单中的用例页面，点击筛选出的用例
        self.chandao_oper.find_cur_case().click()

    def click_operation_button(self):
        #测试单中的用例页面，点击筛选出的用例,再点击执行按钮
        self.chandao_oper.find_operation_button().click()

    def click_fail_option(self):
        #测试单中的批量执行用例页面，点击失败选项
        self.chandao_oper.find_fail_option().click()

    def click_save_button(self):
        #测试单中的批量执行用例页面，点击保存按钮
        self.chandao_oper.find_save_button().click()

    def click_tobug_button(self):
        # 测试单中的用例页面，执行完失败的用例页面，点击转bug
        self.chandao_oper.find_tobug_button().click()

    def click_tobug_button_popup(self):
        # 测试单中的用例页面，转bug弹框页面
        self.chandao_oper.find_tobug_button_popup().click()

    def click_tobug_close_button_popup(self):
        # 测试单中的用例页面，转bug弹框页面,点击关闭
        self.chandao_oper.find_tobug_close_button_popup().click()
        
###以下是测试-bug，提bug页面操作

    def input_bugtitle_textbox(self,bugtitle):
        # bug标题输入
        self.chandao_oper.find_bugtitle_textbox().send_keys(bugtitle)

    def clear_bugtitle_textbox(self):
        # 清空bug标题
        self.chandao_oper.find_bugtitle_textbox().clear()

    def click_iteration_button(self):
        # 点击所属迭代
        self.chandao_oper.find_iteration_button().click()

    def input_iteration_textbox(self,iterationtext):
        # 输入所属迭代
        self.chandao_oper.find_iteration_textbox().send_keys(iterationtext)

    def click_storyIdBox_button(self):
        # 点击相关研发需求
        self.chandao_oper.find_storyIdBox_button().click()
        time.sleep(3)

    def input_storyIdBox_textbox(self,storyIdBoxtext):
        # 输入相关研发需求
        self.chandao_oper.find_storyIdBox_textbox().send_keys(storyIdBoxtext)


    def click_infversion_button(self):
        # 点击影响版本
        self.chandao_oper.find_infversion_button().click()

    def select_infversion_ele(self,ele):
        # 输入影响版本
        time.sleep(2)
        Select(self.chandao_oper.find_iteration_select()).select_by_visible_text(ele)

    def input_infversion_textbox(self,ele):
        # 输入影响版本
        self.chandao_oper.find_infversion_textbox().send_keys(ele)
        time.sleep(3)

    def click_infversion_chosen(self):
        # 点击影响版本
        time.sleep(3)
        self.chandao_oper.find_infversion_chosen_ele().click()

    def click_curappoint_button(self):
        # 点击当前指派
        self.chandao_oper.find_curappoint_button().click()
        time.sleep(3)


    def input_curappoint_textbox(self,ele):
        # 输入当前指派
        self.chandao_oper.find_curappoint_textbox().send_keys(ele)
        time.sleep(2)

    def click_severity_button(self):
        # 点击严重程度按钮
        self.chandao_oper.find_severity_button().click()
        time.sleep(3)

    def click_severity_choice1(self):
        # 点击严重程度1
        self.chandao_oper.find_severity_choice1().click()

    def click_severity_choice2(self):
        # 点击严重程度2
        self.chandao_oper.find_severity_choice2().click()

    def click_severity_choice4(self):
        # 点击严重程度4
        self.chandao_oper.find_severity_choice4().click()

    def click_priority_button(self):
        # 点击优先级按钮
        self.chandao_oper.find_priority_button().click()
        time.sleep(3)

    def click_priority_choice1(self):
        # 点击优先级
        self.chandao_oper.find_priority_choice1().click()

    def click_priority_choice2(self):
        # 点击优先级2
        self.chandao_oper.find_priority_choice2().click()

    def click_priority_choice4(self):
        # 点击优先级4
        self.chandao_oper.find_priority_choice4().click()

    def clear_article_content(self):
        # 清空内容
        self.chandao_oper.find_article_content().clear()

    def input_article_content(self,ele):
        # 输入内容
        self.chandao_oper.find_article_content().send_keys(ele)

    def click_bugsubmit_button(self):
        # 点击当保存按钮
        time.sleep(2)
        self.chandao_oper.find_bugsubmit_button().click()
        time.sleep(2)

    def click_bugreturn_button(self):
        # 点击返回按钮
        time.sleep(5)
        self.chandao_oper.find_bugreturn_button().click()

###以下是测试-用例，操作
    def click_bysearchTab_button(self):
        #测试主页用例页面搜索按钮,click
        self.chandao_oper.find_bysearchTab_button().click()

    def click_field1_chosen_button(self):
        # 点击第一组选项按钮
        self.chandao_oper.find_field1_chosen_button().click()

    def input_field1_chosen_optionbox(self,f1ChoseOpt):
        # 查找并返回测试主页用例页面搜索，第一组选项框
        self.chandao_oper.find_field1_chosen_optionbox().send_keys(f1ChoseOpt)

    def select_field1_judge_selectoption(self,f1JudgeOpt):
        # 查找并返回测试主页用例页面搜索，第一组关系判断按钮
        Select(self.chandao_oper.find_field1_judge_selectoption()).select_by_visible_text(f1JudgeOpt)

    # def find_field1_chosen_optionbox(self):
    #     # 查找并返回测试主页用例页面搜索，第一组选项框
    #     self.chandao_oper.find_element_by_xpath('//div[@id ="field1_chosen"]/a')
    #     return ele

    def click_field1_result_button(self):
        # 查找并返回测试主页用例页面搜索，第一组结果框click
        self.chandao_oper.find_field1_result_button().click()

    def input_field1_result_textbox(self,f1result):
        # 查找并返回测试主页用例页面搜索，第一组结果输入
        self.chandao_oper.find_field1_result_textbox().send_keys(f1result)

    def clear_field1_result_textbox(self):
        # 查找并返回测试主页用例页面搜索，清空第一组结果
        self.chandao_oper.find_field1_result_textbox().clear()

    def input_field1_result_spe_textbox(self,f1result):
        #第二组结果输入框input,在修改者、由谁创建、执行人
        result = re.split('', f1result)
        for i in range(len(f1result)):
            time.sleep(2)
            self.chandao_oper.find_field1_result_spe_textbox().send_keys(result[i+1])
        time.sleep(2)

    def clear_field1_result_spe_textbox(self):
        #第二组结果输入框input,在修改者、由谁创建、执行人
        self.chandao_oper.find_field1_result_spe_textbox().clear()

    def output_field_result_spe_searched_textbox(self):
        #在修改者、由谁创建、执行人时，输入后备选框出现的数据
        self.chandao_oper.find_field_result_spe_searched_textbox()

    def select_fieldlink_judge_selectoption(self,flkChoseOpt):
        #第一组和第二组之间的选项选择
        Select(self.chandao_oper.find_fieldlink_judge_selectoption()).select_by_visible_text(flkChoseOpt)

    def click_field2_chosen_button(self):
        # 查找并返回测试主页用例页面搜索，第二组选项按钮click
        self.chandao_oper.find_field2_chosen_button().click()

    def input_field2_chosen_optionbox(self,f2ChoseOpt):
        # 查找并返回测试主页用例页面搜索，第二组选项框输入
        self.chandao_oper.find_field2_chosen_optionbox().send_keys(f2ChoseOpt)

    # def select_field2_chosen_selectoption(self,f2ChoseOpt):
    #     # 选择第一组选项
    #     Select(self.chandao_oper.find_field2_chosen_selectoption()).select_by_visible_text(f2ChoseOpt)

    def select_field2_judge_selectoption(self, f2JudgeOpt):
        #第二组关系判断按钮
        Select(self.chandao_oper.find_field2_judge_selectoption()).select_by_visible_text(f2JudgeOpt)

    # def find_field2_chosen_optionbox(self):
    #     # 查找并返回测试主页用例页面搜索，第二组选项框
    #     ele = self.driver.find_element_by_xpath('//div[@id ="field1_chosen"]/a')
    #     return ele

    def click_field2_result_button(self):
        #第二组结果框按钮click
        self.chandao_oper.find_field2_result_button().click()

    def input_field2_result_textbox(self,f2result):
        #第二组结果输入框input
        self.chandao_oper.find_field2_result_textbox().send_keys(f2result)

    def input_field2_result_spe_textbox(self,f2result):
        #第二组结果输入框input,在修改者、由谁创建、执行人
        result = re.split('', f2result)
        for i in range(len(f2result)):
            time.sleep(2)
            self.chandao_oper.find_field1_result_spe_textbox().send_keys(result[i+1])
        time.sleep(2)


    def click_case_submit_button(self):
        # 查找并返回测试主页用例页面，搜索按钮
        self.chandao_oper.find_case_submit_button().click()
        time.sleep(2)

    def click_pager_button(self):
        #分页选项按钮click
        self.chandao_oper.find_pager_button().click()

    def click_pager_500_button(self):
        #分页选项中的500按钮,click
        self.chandao_oper.find_pager_500_button().click()

    def get_all_CurPageCases_button(self):
        # 获取当前页面所有用例的可点击标题元素
        self.chandao_oper.find_all_CurPageCases_button()

    def click_first_CurPageCase_button(self):
        # 当前页面第一条用例的可点击标题元素，点击
        self.chandao_oper.find_first_CurPageCase_button().click()

    ##以下是用例详情页面
    def click_testCase_detail_delete_button(self):
        # 查找并返回测试主页用例详情页面，删除按钮,click
        self.chandao_oper.find_testCase_detail_delete_button().click()

    def get_to_alert_accept(self):
        # 接受现有弹框---确认删除用例
        self.chandao_oper.switch_to_alert_accept()

class DelCaseElementScenario(object):
    def __init__(self,driver):
        # 私有方法
        self.chandao_scen = DelCaseElementOper(driver)
        self.chandao_oper = DelCaseElement(driver)

    def login_switch_chandao(self,dic):
        self.chandao_scen.input_account(dic["Account"])
        self.chandao_scen.input_password_textbox(dic["Password"])
        self.chandao_scen.click_submit_button()
        self.chandao_scen.click_xiaoneng_button()
        self.chandao_scen.switch_2_newest_window()
        self.chandao_scen.click_chandao_button()
        self.chandao_scen.switch_2_newest_window()

    def mark_case_import_bug(self,dic,data1,rangexlsm,rangexlsmafter):
        self.chandao_scen.click_ceshi_button()
        self.chandao_scen.click_ceshidan_button()
        self.chandao_scen.click_currentItem_button()
        self.chandao_scen.input_currentItem_textbox(dic["Directory"])
        self.chandao_oper.operate_enter()
        if dic["Csdshunxu"] == '1':
            self.chandao_scen.click_ceshidan_case1_button()
        elif dic["Csdshunxu"] == '2':
            self.chandao_scen.click_ceshidan_case2_button()
        elif dic["Csdshunxu"] == '3':
            self.chandao_scen.click_ceshidan_case3_button()
        elif dic["Csdshunxu"] == '4':
            self.chandao_scen.click_ceshidan_case4_button()
        self.chandao_scen.click_bysearchTab_button()
        self.chandao_scen.click_field1_chosen_button()
        self.chandao_scen.input_field1_chosen_optionbox('用例编号')
        self.chandao_oper.operate_enter()
        for i in range(len(data1)):
            Bugtitle = data1[i][0]
            Bugcontent = data1[i][1]
            Severity = data1[i][2]
            dymcappoint = data1[i][3]
            Casecode = int(data1[i][4])
            self.chandao_scen.clear_field1_result_textbox()
            self.chandao_scen.input_field1_result_textbox(Casecode)
            self.chandao_scen.click_case_submit_button()
            if self.chandao_oper.find_cur_result() != '失败':##
                print('这是个未执行为失败的用例，标注成失败')
                self.chandao_scen.click_cur_case()
                self.chandao_scen.click_operation_button()
                self.chandao_scen.click_fail_option()
                self.chandao_scen.click_save_button()
            self.chandao_scen.click_tobug_button()
            self.chandao_oper.frame_to_tobug()
            self.chandao_oper.operate_pagedown()
            self.chandao_scen.click_tobug_button_popup()
            self.chandao_oper.switch_newest_window()
            self.chandao_scen.click_curappoint_button()
            if dymcappoint == None:
                self.chandao_scen.input_curappoint_textbox(dic["Curappoint"])
            else:
                self.chandao_scen.input_curappoint_textbox(dymcappoint)
            self.chandao_oper.operate_enter()
            self.chandao_scen.clear_bugtitle_textbox()
            self.chandao_scen.input_bugtitle_textbox(Bugtitle)
            ##此处补充严重程度筛选
            if Severity == 1:
                self.chandao_scen.click_severity_button()
                self.chandao_scen.click_severity_choice1()
                self.chandao_scen.click_priority_button()
                self.chandao_scen.click_priority_choice1()
            elif Severity == 2:
                self.chandao_scen.click_severity_button()
                self.chandao_scen.click_severity_choice2()
                self.chandao_scen.click_priority_button()
                self.chandao_scen.click_priority_choice2()
            elif Severity == 4:
                self.chandao_scen.click_severity_button()
                self.chandao_scen.click_severity_choice4()
                self.chandao_scen.click_priority_button()
                self.chandao_scen.click_priority_choice4()
            else:
                pass
            self.chandao_oper.frame_to_reprosteps()
            self.chandao_scen.clear_article_content()
            self.chandao_scen.input_article_content(Bugcontent)
            self.chandao_oper.frame_to_default()
            self.chandao_oper.operate_pagedown()
            self.chandao_oper.operate_pagedown()
            self.chandao_scen.click_bugsubmit_button()
            self.chandao_oper.close_cur_window()#到这一步已经成功
            self.chandao_oper.switch_newest_window()
            self.chandao_scen.click_tobug_close_button_popup()
            dyrange = ['D'+str(i+rangexlsm+2)+rangexlsmafter]
            readexcelcasetobug.wirte_range(dyrange)